<?php echo $header; ?>
<div class="box">
  <div class="content">
    <h2 class="h2title">
      Create New Department
    </h2>
	<div>
		<div class="warning" style="margin-top:10px;display:none;" >			
		</div>
		<table style="width:100%;padding:20px;">
			<tr>
				<td>
					<span class="spanlablebold">
						Department Code
					</span>
					<input type="text" id="txtdeptcode" name="txtdeptcode" maxlength="50" class="txt"/>
				</td>
				<td>
					<span class="spanlablebold">
						Department Name
					</span>
					<input type="text" id="txtdeptname" name="txtdeptname" maxlength="50" class="txt"/>
				</td>
			</tr>
		</table>
	</div>
  </div>
</div>
<div class="buttonbar">
	<input type="button" value="Save" id="btnsave" name="btnsave" class="btnradius" style="margin-right:10px;"/>
	<input type="button" value="Reset" id="btnreset" name="btnreset" class="btnradius"/>
</div>	
<script type="text/javascript">
	 $("#btnsave").click(function(){
	 	$(".warning").hide();
	 	if(validate()){
		  	loading("show");
			   $.ajax({
                url: "<?php echo MAIN_PAGE.'department/departmentpost';?>",
                type: 'POST',
                data: {
                  deptcode:$("#txtdeptcode").val(),
				  deptname:$("#txtdeptname").val()
                },
                dataType: 'json',
                success: function(res){
                    loading('hide');
					if(res.status){					
						$("#btnreset").trigger("click");
					    alert(res.msg);
					}
					else{
					    alert(res.msg);	
					}               
                }
            });
		}
	 });
	 
	 $("#btnreset").click(function(){
	 	$("#txtdeptcode").val('');
		$("#txtdeptname").val('');
	 });
	 
	 function validate(){
	 	if($("#txtdeptcode").val()==""){
			$("#txtdeptcode").focus();
			$(".warning").text("Please enter department code").show();
			return false;
		}
		if($("#txtdeptname").val()==""){
			$("#txtdeptname").focus();
			$(".warning").text("Please enter department name").show();
			return false;
		}
		return true;			
	 }
</script>		
<?php echo $footer;?>